/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entreprise;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import mapping.DBPatient;

/**
 *
 * @author Quoc-Khai
 */
public class PatientService {
    public boolean createPatient(int patientID, String patientName, String patientSex, Date patientDateOfBirth, String patientJob, String patientAddress, String patientPhoneNumber, String patientEmail, float patientHeight, float patientWeight, String patientBloodType) throws SQLException{
        DBPatient dbPatient = new DBPatient();
        Patient iPatient = new Patient();
        iPatient = dbPatient.getPatient(patientID);
        if (iPatient.getPatientID().length() <= 0) {
            iPatient.setPatientName(patientName);
            iPatient.setPatientSex(patientSex);
            iPatient.setPatientDateOfBirth(patientDateOfBirth);
            iPatient.setPatientJob(patientJob);
            iPatient.setPatientAddress(patientAddress);
            iPatient.setPatientPhoneNumber(patientPhoneNumber);
            iPatient.setPatientEmail(patientEmail);
            iPatient.setPatientHeight(patientHeight);
            iPatient.setPatientWeight(patientWeight);
            iPatient.setPatientBloodType(patientBloodType);
            
            dbPatient.createPatient(iPatient);
            return true;
        }
        
        System.out.println("Patient existe!");
        return false;
    }
    public boolean deletePatient(int patientID) throws SQLException{ 
        DBPatient dbPatient = new DBPatient();
        Patient iPatient = new Patient();
        iPatient = dbPatient.getPatient(patientID);
        if (iPatient.getPatientID().length() > 0) {
            dbPatient.deletePatient(patientID);
            return true;
        }
        
        System.out.println("Patient not existe!");
        return false;
    }
    public boolean updatePatient(int patientID,String patientName, String patientSex, Date patientDateOfBirth, String patientJob, String patientAddress, String patientPhoneNumber, String patientEmail, float patientHeight, float patientWeight, String patientBloodType) throws SQLException{
        DBPatient dbPatient = new DBPatient();
        Patient iPatient = new Patient();
        iPatient = dbPatient.getPatient(patientID);
        if (iPatient.getPatientID().length() > 0) {
            iPatient.setPatientID(String.valueOf(patientID));
            iPatient.setPatientName(patientName);
            iPatient.setPatientSex(patientSex);
            iPatient.setPatientDateOfBirth(patientDateOfBirth);
            iPatient.setPatientJob(patientJob);
            iPatient.setPatientAddress(patientAddress);
            iPatient.setPatientPhoneNumber(patientPhoneNumber);
            iPatient.setPatientEmail(patientEmail);
            iPatient.setPatientHeight(patientHeight);
            iPatient.setPatientWeight(patientWeight);
            iPatient.setPatientBloodType(patientBloodType);
            
            dbPatient.updatePatient(iPatient);
            return true;
        }
        
        System.out.println("Patient not existe!");
        return false;
    }
    public List<Patient> findPatients(String patientName){
        List<Patient> patients=null;       
        return patients;
    }
}
